package com.yckj.day02;

/**
 * TODO 数据类型的转换
 *
 * @author shengyuee
 * @version 1.0
 * 2025/7/17 10:00
 */
public class Demo1 {
    public static void main(String[] args) {
        byte b1 = 34;
        byte b2 = 56;
        // 强制类型转换
        byte b3 = (byte) (b1 + b2);
        // 自动类型转换
        short s1 = b2;
        char ch1 = 'A';
        char ch2 = 97;
        System.out.println("ch1 = " + ch1);
        System.out.println("ch2 = " + ch2);
        // 自动类型转换
        int i1 = ch1;
        int i2 = ch2;
        System.out.println("i1 = " + i1);
        System.out.println("i2 = " + i2);
        // 强制类型转换
        char ch3 = (char) i1;
        float f1 = 3.56F;
        // 强制类型转换， 会损失精度
        i1 = (int) f1;
        // long<->double
        long num1 = 234;
        // 自动类型转换
        double d1 = num1;
        // 强制类型转换
        long num2 = (long) d1;

        short s11 = 12;
        // 强制类型转换
        short s22 = (short) (s11 + 1);
        s11 += 1; // s11 = s11 + 1;
        double d3 = 3/2;
        System.out.println("d3 = " + d3);
        double d4 = 3.0/2;
        System.out.println("d4 = " + d4);
    }
}
